package com.johnguo.carbondata_demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 启动命令：spark-submit --conf spark.sql.hive.thriftServer.singleSession=true --class org.apache.carbondata.spark.thriftserver.CarbonThriftServer ./carbonlib/carbondata_2.10-1.1.0-shade-hadoop2.2.0.jar hdfs://master:9000/usr/cardata
 * @author 10
 *
 */
public class CarbonJdbcDemo {
	private static String driverName = "org.apache.hive.jdbc.HiveDriver";
	
	public static void main(String...args) throws Exception {
		Class.forName(driverName);
		Connection con = DriverManager.getConnection("jdbc:hive2://master:10000/default", "", "");
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("select * from sale order by total_pay desc limit 10");
		for(int n=0;n<rs.getMetaData().getColumnCount();n++) {
			System.out.print(rs.getMetaData().getColumnName(n+1) + "	");
		}
		System.out.println();
		while(rs.next()) {
			for(int n=0;n<rs.getMetaData().getColumnCount();n++) {
				System.out.print(rs.getString(n+1) + "	");
			}
			System.out.println();
		}
	}
}
